import messageApi from "../services/message";
const namespace = "message";
const selectState = (state) => state[namespace];
export default {
  namespace,
  state: {
    list: [],
    noticeType: 1,
  },
  reducers: {
    overrideStateProps(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    updateStateProps(state, { payload }) {
      const { name, value } = payload;
      return {
        ...state,
        ...{ [name]: { ...state[name], ...value } },
      };
    },
  },
  effects: {
    *questMassage(action, { call, put, select }) {
      const { noticeType } = yield select(selectState);
      const params = {
        noticeType,
      };
      let res = yield call(messageApi.questMassage, params);
      console.log("res", res);
      if (res.code === 30000) {
        yield put({
          type: "overrideStateProps",
          payload: {
            list: res.data,
          },
        });
      }
    },
  },
  subscriptions: {},
};
